package com.factors.DaiGuiCheng.Learning_Disabilities;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

public class ExamScoreFilterMapper extends Mapper<LongWritable, Text, Text, IntWritable> {

    private static final IntWritable one = new IntWritable(1);

    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        if (key.get() == 0) return; // Skip header line

        String[] columns = value.toString().split(",");
        if (columns.length >= 20) {
            try {
                float examScore = Float.parseFloat(columns[19]); // Exam_Score is the 20th column
                String learningDisabilities = columns[15]; // Learning_Disabilities is the 16th column

                if (examScore > 80) {
                    context.write(new Text(learningDisabilities), one);
                }
            } catch (NumberFormatException e) {
                // Handle non-numeric values or other parsing errors
            }
        }
    }
}